import glob
import os

import eyed3

from connect_database.music_tools import MusicTool


class MusicInformationGetter:

    def __init__(self, file_path):
        self.music_name = None
        self.singer = None
        self.music_label = None
        self.duration = None
        self.file_path = file_path
        self.file_name, self.file_format = os.path.splitext(self.file_path)

    def get_music_info(self):
        # 文件存在
        music = eyed3.load(self.file_path)
        # 音乐信息存放表
        if not music:
            return
        try:
            self.music_name = music.tag.title  # 获取音乐名
            self.singer = music.tag.artist
            if not self.music_name:
                self.music_name = '未知专辑名'
            if not self.singer:
                self.singer = '未知歌手'
            self.music_label = "未知"
            self.duration = int(music.info.time_secs)
            return self.music_name, self.singer, self.music_name, self.music_label, self.duration
        except Exception as e:
            print(e)
        return None, None, None, None


if __name__ == '__main__':
    # music_list = load_music("单车_陈奕迅_流行")
    m = MusicInformationGetter("../audio/11_黄礼格_流行.mp3")
    m.find_folder()
